package com.atguigu.educms.controller;


import com.atguigu.common.R;
import com.atguigu.common.cron.bean.FrontPageBean;
import com.atguigu.common.cron.vo.QuestionQueryVo;
import com.atguigu.educms.entity.QaAnswer;
import com.atguigu.educms.service.QaAnswerService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 问题--回帖详情表 前端控制器
 * </p>
 *
 * @author Panghl
 * @since 2021-03-14
 */
@RestController
@RequestMapping("/educms/qa-answer")
public class QaAnswerController {

    @Autowired
    private QaAnswerService answerService;

    @ApiOperation(value = "回帖")
    @PostMapping("/reply")
    public R reply(@RequestBody(required = false) QaAnswer answer) {
        try {
            if (!StringUtils.isEmpty(answer)) {
                answerService.save(answer);
                return R.ok();
            }
            return R.error();
        }catch (Exception e){
            return R.error();
        }
    }

    @ApiOperation(value = "回帖子列表")
    @PostMapping("/getQuestionList/{pageNo}/{pageSize}")
    public R getQuestionList(@PathVariable("pageNo") Integer pageNo,
                             @PathVariable("pageSize") Integer pageSize,
                             @RequestParam Integer questionId) {
        FrontPageBean frontPageBean= answerService.getAnswerAnd2Answer(pageNo, pageSize,questionId);
        return R.ok().data(frontPageBean);
    }
}
